package com.lwq.controller.system;

import com.lwq.annotation.PermissionController;
import com.lwq.annotation.PermissionInterface;
import com.lwq.annotation.RepeatSubmit;
import com.lwq.controller.BaseController;
import com.lwq.model.Dto;
import com.lwq.model.Dtos;
import com.lwq.model.Result;
import com.lwq.model.SysUser;
import com.lwq.service.system.UserService;
import com.lwq.util.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2021/6/11
 */
@RestController
@PermissionController(type="system")
public class UserController extends BaseController {

    @Autowired
    private UserService service;

    @GetMapping(value="/user/list")
    @PermissionInterface(code="user.query", name="查询用户")
    public TableDataInfo list(){
        Dto dto = Dtos.newDto(request);
        startPage();
        return getDataTable(service.list(dto));
    }

    @PutMapping(value="/user")
    @RepeatSubmit
    @PermissionInterface(code="user.update", name="更新用户")
    public Result update(@RequestBody SysUser user){
        service.update(user);
        return Result.ok();
    }

    @DeleteMapping(value="/user")
    @PermissionInterface(code="user.delete", name="删除用户")
    public Result remove(@RequestParam Long id){
        service.delete(id);
        return Result.ok();
    }
}
